import {
  exportUrl,
  getPropertieIdList,
  getYesOrNotList,
} from "@/api/materials/mesCharacteristic";
import { checkStr } from "@/utils/judge";
// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t("common.export"),
    type: "primary",
    icon: "el-icon-download",
    handleName: "export", //点击时返回的标识
    url: exportUrl,
    //auth: "auth:operlog:export", //权限字段
  },
  {
    name: $i18n.t("common.add"),
    type: "primary",
    icon: "el-icon-circle-plus-outline",
    handleName: "add", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    icon: "el-icon-delete",
    handleName: "deleteBatch", //点击时返回的标识
    isMultiple: true,
    disabled: (data) => {
      return !data.length > 0;
    },
  },
  {
    name: $i18n.t("mesCharacteristic.enable"),
    type: "success",
    icon: "el-icon-unlock",
    handleName: "publish", //点击时返回的标识
    isMultiple: true, //至少选择一条
    //是否可点击；
    disabled: (data) => {
      return data.length != 1;
    },
  },
  {
    name: $i18n.t("mesCharacteristic.deactivate"),
    type: "warning",
    icon: "el-icon-lock",
    handleName: "deactivate", //点击时返回的标识
    isMultiple: true, //至少选择一条
    //是否可点击；
    disabled: (data) => {
      return data.length != 1;
    },
  },
];
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
];
// 搜索条件配置
export const searchConfig = {
  inline: true,
  formDesc: {
    propertieId: {
      type: "select",
      label: $i18n.t("mesCharacteristic.propertyId"),
      prop: {
        value: "id",
        text: "propName",
      },
      options: async (data) => {
        const list = await getPropertieIdList({ activeFlag: "1" });
        return list.data.result;
      },
    },
    characteristicCode: {
      type: "input",
      label: $i18n.t("mesCharacteristic.characteristicCode"),
    },
    activeFlag: {
      type: "select",
      label: $i18n.t("mesCharacteristic.activeFlag"),
      prop: {
        value: "value",
        text: "description",
      },
      options: async (data) => {
        const list = await getYesOrNotList();
        return list.data.result;
      },
    },
  },
};
var validatePass = (rule, value, callback) => {
  setTimeout(() => {
    if (!checkStr(value, "english-number")) {
      callback(new Error($i18n.t("mesCharacteristic.rule8")));
    } else {
      callback();
    }
  }, 100);
};
// 新增/删除表单配置
export const formDescDialog = {
  span: 24,
  disabled: false,
  isShowSubmitBtn: true,
  rules: {
    characteristicCode: [
      { validator: validatePass, trigger: ["change", "blur"] },
    ],
  },
  formDesc: {
    propertieId: {
      type: "select",
      label: $i18n.t("mesCharacteristic.propertyId"),
      layout: 12,
      required: true,
      prop: {
        value: "id",
        text: "propName",
      },
      options: async (data) => {
        const list = await getPropertieIdList({ activeFlag: "1" });
        return list.data.result;
      },
    },
    characteristicCode: {
      type: "input",
      label: $i18n.t("mesCharacteristic.characteristicCode"),
      layout: 12,
      disabled: (d) => !!d.id,
      required: true,
    },
    characteristicName: {
      type: "input",
      label: $i18n.t("mesCharacteristic.characteristicName"),
      layout: 12,
      required: true,
    },
    activeFlag: {
      type: "switch",
      label: $i18n.t("mesCharacteristic.activeFlag"),
      layout: 12,
      required: false,
      valueFormatter(labels) {
        return labels == "1" ? "1" : "0";
      },
      displayFormatter(labels) {
        return labels == "1" ? true : false;
      },
    },
    remark: {
      type: "textarea",
      label: $i18n.t("common.remark"),
      layout: 24,
      required: false,
    },
  },
};
